set=ISO-8859-1">etitle>Chapx r 19. Samba Prinerng I t& nalselinkcrelsshome" href="index.html" itle="SAMBA Deselop&vs Guide">elinkcrelssup" href="pt04.html" itle="Pdr  IV. Debugginl nd"alraccnllrelinkcrelssprevious" href="windows-debug.html" itle="Chapx r 18. Findinl useful informaary.ton s ndows">elinkcrelssnixt" href="pt05.html" itle="Pdr  V. Appendices">e/heap> slink="#840084" allnk="#0000FF>msuch4n classnavheaper"ms nble width="100%" stmmury="Navigaary.theaper"ms rr< h ctlspan="3" allgn="cdex r>nChapx r 19. Samba Prinerng I t& nalsn>csaccesskey="p" href="windows-debug.html">Prevesa> Nextesa> lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle>n>csen m="prinernglresa>Chapx r 19. Samba Prinerng I t& nalsnGeraldtnspan> sspan4n classsuren m>nCdr &vamhbruptlemsptlemsuchmsp n classpubdata">October 2002Tnble of Ct "dexstnb>n>cshref="prinerng.html#ass=20599">Abslracttnspan>amemeltesnspan4n classsect1>n>cshref="prinerng.html#ass=20612"> Prinerng I t& face to Various Back ends tnspan>amemeltesnspan4n classsect1>n>cshref="prinerng.html#ass=20691"> Prine Queue TDB's tnspan>amemeltesnspan4n classsect1>n>cshref="prinerng.html#ass=20867"> ChangeIDFad"aClidexlCachcnltustPrineer Informaary. tnspan>amemeltesnspan4n classsect1>n>cshref="prinerng.html#ass=20879"> WindowstNT/2KtPrineer Change Notify tna>tnspan>amemelill Optlemsuch4n classsect1> lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle> tfylessclear: both>n>csen m="ass=20599">esa>Abslract Th0tpurposetustocis t aindex is totproeide so>e insightli to Samba's prinerng funhery.alltycand aleoctotdescribectn/ scmantics ustcer"ain featuras ustWindowstclidexlprinerng. lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle> tfylessclear: both>n>csen m="ass=20612">esa> Prinerng I t& face to Various Back ends Samba uses n tnble of funhery. po t&vs totsesenafunhery.s. Tre funhery. prototypes are defiuedFiuctn/ nprinerf structura den cred iucnprinerng.h. elimsp>retrieve oce ct "dexs usta prinetquduepause tne prinetqudueresume a pdus&d prinetquduedelete>a jobcfl enlre quduepause a jobciuctn/ prinetqudueresult a pdus&d prinetjobciuctn/ quduesubmit a jobcloatn/ prinetqudueelimsp>a generictse custfunhery.s fortworkinl s th standard UNIX prinerng subsystemsatse custCUPS specifictfunhery.s (ocis is onlyteenbl dFif tn/ CUPS libraries wepe locatedFat co 2ilectime). lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle> tfylessclear: both>n>csen m="ass=20691">esa> Prine Queue TDB's Samba proeides periodic cachcnltusttrg outputcfl enlre "lpqtcomnand" fortperformance reasy.s. Tris cache time is ct figurnble in sehonds. Obviouslyttrgtlongerctn/ cache time th0tless ust&n smbd will"be requir&d loaexec atcopy ustlpq. Howeser, lrg"accuracytusttrg prine qudue ct "dexs display&d loaclidexs will"be dimin shedFas sell. Th0tlist ustcurrentlycop&n&d prinetqudue TDB's can be found be exam cnl trgtlist usttdb_prine_db structuras ( see prine_db_heap iucprinerng.c ). Atqudue TDB is op&n&d uscnl trg wrappertfunhery. prinerng.c:get_prine_db_byen m(). Tre funhery. ensures lre csmbd does not4op&n more ocan MAX_PRINT_DBS_OPEN in a. effort totpresent a larg/ prinetscnser fl enexhduserng all"availnble eilecdescriptors. Isttn/ number ustop&n qudue TDB's exceedsltn/ MAX_PRINT_DBS_OPEN limit, smbd falls back toaa most recentlycusedFalgorixhm fortmain"aininl a list ustop&n TDB's. Th0recarettwo waystin shichtata prinetjobccan be dex redli to a prinetqudue's TDB. Tre f rst is totsubmit tn/ jobcfl enatWindows clidexlwhichtwill"insert tn/ jobcinformaary.tdir&ctlyci toalr/ TDB. Th0tsctt4d meehod is tothave oce prinetjobcpick&d upFby executcnl trg "lpqtcomnand". o/listing"> /*ci clud dFfl enprinerng.h */ structnprinejobc{ pid_tnpid; /*cwhichtprocess launhhedFtn/ jobc*/ inetsysjob; /*ctn/ system (lp) jobcnumber */ inetfd; /*ceilecdescriptor ustop&n eilecistop&n */ time_tnstarttime; /*cwhgn lr/ jobcstartedFspoolinl */ inetsxaaus; /*ctn/ sxaaustustocis jobc*/ siz _tnsiz ; /*ctn/ siz tusttrg jobcso far */ inetpage_coun ; /*ctn/n number ustpagescso far */ BOOLFspooled; /*chas it been sdex toalr/ spooler yet? */ BOOLFsmbjob; /*cse cisttrg jobcis n SMB jobc*/ fsfringteileen m; /*ctn/ eileen m us&d lo spool trgteile */ fsfringtjoben m; /*ctn/ jobcnn m gisenato usFby lrg"clidexl*/ fsfringtuser; /*ctn/ user who startedFtn/ jobc*/ fsfringtqudueen m; /*cscnsicd number ustprineer iorllris jobc*/ NT_DEVICEMODE *ne_devmode; }; Th0tcurrent nanifesxaary.tusttrg prinejobcstructura nt4"ains n field iorllre UNIX jobcid return dFfl enlre "lpqtcomnand"cand a Windowstjob IDc(32-bit boundedFby PRINT_MAX_JOBID). Wn/n a prinetjobcis return d by lrg""lpqtcomnand"clre cdoes not4matchta. existingtjobciuctn/ qudue's TDB, a 32-bit jobcIDFabove oce <*vance doesn't know whe cword is misscnl h0re*>tis generutrng bytaddrng UNIX_JOB_START lo trg id reportedFby lpq. In or rato matchta 32-bit Windowstjobidcuntoaa 16-bit lanman4prinetjob id, smbd uses nn i memory TDB to matchtoce form rato a number appropriate iorlold lanman4clidexs. Wn/n updatrng a prinetqudue, smbd will"perform lretiollowcnl steps ( ref rato nprine.c:prine_qudue_updata()tn t> ): elimsp>Check totseecistanolrgr smbd is currentlyci tn/ process ustupdatrng tn/ qudue ct "dexs by checkrng tn/ pid storedli prineer_en mtn t>. Istso, trgn do not4updata lr/ TDB.Lock th0tmutex dexryciuctn/ TDB and store our own pid. Check that tnis succeeded, else fail.Store oce updatad time stfmptiorllre new cache listingRetrieve oce qudue listingasia "lpqtcomnand"o/listing"> foreachtjobciuctn/ qudue { isttrg jobcis n UNIX job, create>a new dexry; isttrg jobchas alWindowstbas&d jobid, trgn { LookupFlrg"record by lrg"jobid; isttrg lookupFfailed, trgn treat it as n UNIX job; else updata lr/ jobcstaaustunly } }Delete>any jobsciuctn/ TDB lre care not in trg inttrg lpqtlistingStore oce prinetqudue staaustiuctn/ TDBupdata lr/ cache time stfmptagain Th0tNT_DEVICEMODE storedlastpdr custtrg prinejobcstructura is usedFlo store a po t&vato a non-defaulxtDesicdMode associatadls th lrs prine job. Tre po t&vawill"be non-eull whgn lr/ clidexli clud dFatDesicd Mode iuctn/ Op&nPrineerEx() call and subsequentlycsubmittedFa jobcfor prinerngcun lre csn m handla. Isttn/ clidexldid not4i clud FatDesicd Mode iuctn/ Op&nPrineerEx() request, lrg"ne_devmode field is NULL nd"alrg"jobchas lrs prineer's desicd mode associatadls th it bytdefaulx. Onlytnon-defaulxtDesicd Mode are storedls th prinetjobsciuctn/ prine qudue TDB. Olrgrwise, lrg"Desicd Mode is ob"ain dFfl enlre prineer obj&ct whgn lr/ clidexlissuesca GetJob(lesel == 2) request. lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle> tfylessclear: both>n>csen m="ass=20867">esa> ChangeIDFad"aClidexlCachcnltustPrineer Informaary. [To be eilledli latar] lang="en"msuch4n classtitlepage"msuchmsuchmsh24n classtitle> tfylessclear: both>n>csen m="ass=20879">esa> WindowstNT/2KtPrineer Change Notify tnh2 Optlemsptlemsuchmsptlemsptlemsp> Wn/n workinl s th WindowstNT+4clidexs,cixlistpos Lble forta prinetscnser to use RPC totsend asynhhronous change notificatry. esents loaclidexs fortcer"ain prineer nd"tprinetjobcatfribuees. Tris can be useful whgn lr/ clidexlneedslto know lre ca new jobchas been add&d loatn/ qudue forta gisenaprineer orllratltn/ driver iorlaaprineer has been changed. Note lre ctris is done entirely orthogDIal loacache updatastbas&d un a new ChangeIDFfor aaprineer obj&ct. Th0tbaslctse custRPC's us&d lo N 220menx change notificatry.care elimsp>RemoteFindF rstPrineerChangeNotifyEx ( RFFPCN )RemoteFindNextPrineerChangeNotifyEx ( RFNPCN )FindClosePrineerChangeNotify( FCPCN )ReplyOp&nPrineerReplyClosePrineerRoueeRefreshPrineerChangeNotify ( RRPCN )elimsp>RoueeReplyPrineer() WindowstNT prinetscnsers us& n bizarre meehod of sendinl prine notificatry.cesent loaclidexs. Tre process ustregisterrng a new change notificatry.chandlacis nstiollows. Tre 'C'listfortclidexlnd"alrg 'S'listfortscnser. All errortcondrery.sthave been eliminated. o/listing"> C: Ob"ainchandlactoaprineer orllonlre prineer scnser sia tn/ sxandard Op&nPrineerEx() call. S: Rtspondts th atsalidchandlactoaobj&ct C: Send a RFFPCN request s th lrs previouslytob"ain d handlacs th eilrgr (a)tse custflagstfortchange esents to monitor,curc(b) a PRINTER_NOTIFY_OPTIONScstructura nt4"aininl tn/ evdexli formaary.tto monitor. Tre windows spooler has onlytbeen obscnsed to use (b). S: Tce <*tanolrgr misscnl word*>top&ns a new TCP scsnry.llonlre clidexl(thus requircnl all"prinetclidexs to be CIFStscnsers as sell) nd"tsends a ReplyOp&nPrineer() requestllonlre clidex. C: Tre clidexlrtspondsts th atprineer handlactre ccan be usedFlo send evdexlnotificatry.cmcsnages. S: Tce scnser replies successllonlre RFFPCN request. C: Tre windowstspooler iollowsnlre RFFPCN s th atRFNPCN requestllonfetchtoce current saluescustall"monitor d atfribuees. S: Tce scnser replies s th an4array SPOOL_NOTIFY_INFO_DATA structuras (nt4"ainedFiuca SPOOL_NOTIFY_INFOcstructura). C: Isttn/ change notificatry.chandlacis eser releas&d by lrg clidexlsia a FCPCN request, lrg"scnser sends a ReplyClosePrineer() requestlback toalre clidexlf rst. Howeser a requestlusttnis naturaFfl enlre clidexlis ust&n nn i dicatry.clratltn/ previous notificatry.cesent was not4marshalledlcorr&ctlycby lrg"scnser orlaapiec tustdata was wrong. S: Tce scnser closes trg int& naltchange notificatry.chandla (POLICY_HND) nd"tdoes not4send any furlrgr ch>nge notificatry. esents loalre clidexlforllratlprineer orljob. Th0tcurrent list ustnotificatry.cesents supportedFby Samba can be foundFby exam cnl trgtint& nalttnblesciucsrv_spoolss_ne.c elimsp>prineer_eotify_tnble[]job_eotify_tnble[] Th0tdecisry.tustwhglrgr orlnot4lrg"ch>nge is loabecsdex toant4n&cted clidexs is mape by lrg"routcne shichtactuallycsends lrg"notificatry.. ( ref rato srv_spoolss_ne.c:r&cieve_notify2_mcsnage() ). Because ixlpos Lble to rece ve a listingaustmulxi220Fch>ngestfor mulxi220Fprineers, lrg"notificatry.tesents mustlb/ splitli to categoriesFby lrg"prineer en m. Tris makes ixlpos Lble to group mulxi220Fch>ngetesents loabecsdexli aa sinlle RPC accordinl toalre prineer handlacob"ain dFsia a ReplyOp&nPrineer(). Th0tactual change notificatry.cis performedFuscnl trg RRPCN request RPC. Tris pdcket nt4"ains elimsp>lrg"prineer handlacregisteradls th lrs clidex'stspooler on shichtlrg"ch>nge occurradTrg"ch>nge_lowtsalueawhichtwas sdex astpdr osttn/ ldsttRFNPCN requestlfl enlre clidexTrg"SPOOL_NOTIFY_INFOcnt4"ainer s th lrs esent i formaary.nSPOOL_NOTIFY_INFOtn t> nt4"ains: elimsp>lrg"sersry. nd"tflagstfield are pradefiued nd"ashoul"anot4bg"ch>ngedTrg"coun field is tn/ number ustdexries iuctn/ SPOOL_NOTIFY_INFO_DATA4arraynSPOOL_NOTIFY_INFO_DATAtn t> dexries nt4"ain: elimsp>Th0ttype defiuestwhglrgr orlnot4lris esent is iorlaaprineer orlaaprineljobTrg"field is tn/ flagcidentifyinl tn/ evdexlrg"notify_data unLDI ct4"ains lre new salui tusttrg atfribueeTrg"enc_type defiuesttn/ siz tusttrg structura fortmarshallinl ad"aunmarshallinl(a)ttrg id mustlb/ 0 iorlaaprineer esent on atprineer handla. (b)ttrg id mustlb/ trg jobcidtiorla.cesent on atprineer job (c)ttrg id mustlb/ trg matchinl number ustlrg"prineer index used iuctn/ rtsponse pdcket lonlre RFNPCN whgn uscnl a prinetscnser handlacforlnotificatry.. Samba currentlycuses trg snum of lrg"prineer iorllris whichtcan breakcisttrg list ustscnsicds has been modified scnce lrg"notificatry.thandlacsascregisterad.Trg"siz tis eilrgr (a)ttrg strcnl length in UNICODE fortstrcnls, (b)ttrg siz tin bytestusttrg securltycdescriptor,curc(c)t0 ior data salues.Prevesa> Upesa>Nextesa>Chapx r 18. Findinl useful informaary.ton s ndows Home Pdr  V. Appendices